package com.atguigu.oss.controller;

import com.atguigu.commonutils.R;
import com.atguigu.oss.service.OssService;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@CrossOrigin
@RequestMapping("/eduoss/fileoss")
public class OssController {

    private OssService ossService;
    @Autowired
    public void setOssService(OssService ossService) {
        this.ossService = ossService;
    }

    //上传头像的方法
    @PostMapping("/uploadAvatar")
    public R uploadOssFile(
            @ApiParam(name = "file", value = "文件", required = true)
            @RequestParam("file") MultipartFile file){
        String url = ossService.uploadFileAvatar(file);
        return R.ok().data("url",url);
    }

//    @PostMapping("/uploadAvatar")
//    public R uploadOssFile(
//            @RequestHeader("content-type") String header){
//        System.out.println(header);
//        return R.ok();
//    }
}
